package test.xml;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.GregorianCalendar;

import jakarta.xml.bind.annotation.adapters.XmlAdapter;


//XmlAdapter对LocalDateTime支持不是很好
public class XmlDateAdapter extends XmlAdapter<GregorianCalendar ,LocalDateTime>   {
	
	public static final String FORMATTER_STANDARD = "yyyy-MM-dd HH:mm:ss";

	@Override
	public LocalDateTime unmarshal(GregorianCalendar gregorianCalendar) {
		return gregorianCalendar == null ? null : gregorianCalendar.toZonedDateTime().toLocalDateTime();
	}

	@Override
	public GregorianCalendar marshal(LocalDateTime localDateTime) {
		return localDateTime == null ? null : GregorianCalendar.from(localDateTime.atZone(ZoneOffset.UTC));
	}
	

}
